package config

import (
	"gopkg.in/yaml.v2"
	"io/ioutil"
)

type MySQLStruct struct {
	Host     string
	Port     string
	User     string
	Password string
	DB       string
}

type RedisStruct struct {
	Host     string
	Port     string
	Password string
	DB       int
}

type StorageTimeStruct struct {
	Ip    int
	Token int
}

type CountStruct struct {
	MaxFailToken            int
	MaxRequest              int
	MaxLimitBucket          int
	OnceLimitBucketIncr     int
	LimitBucketIncrInterval int
}

type EnvStruct struct {
	DevMode             bool
	Appid               string
	Secret              string
	Port                string
	UploadPath          string
	UploadSize          int64
	DefaultServerStatus int
}

type MyConfigStruct struct {
	Mysql       MySQLStruct
	Redis       RedisStruct
	StorageTime StorageTimeStruct
	Count       CountStruct
	Env         EnvStruct
}

var config MyConfigStruct

func GetMySQL() MySQLStruct {
	return config.Mysql
}

func GetRedis() RedisStruct {
	return config.Redis
}

func GetStorageTime() StorageTimeStruct {
	return config.StorageTime
}

func GetCount() CountStruct {
	return config.Count
}

func GetEnv() EnvStruct {
	return config.Env
}

func init() {
	data, err := ioutil.ReadFile("./config.yml")
	if err != nil {
		panic(err)
	}
	err = yaml.Unmarshal(data, &config)
	if err != nil {
		panic(err)
	}
}
